<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

//Route::middleware('auth:api')->get('/user', function (Request $request) {
//    return $request->user();
//});

/*
	Api模块
*/


Route::group(['middleware'=>[]], function () {

    Route::any('/{controller}/{action}', function ($controller, $action) {
        $request = app('request');
        $controller = 'App\Http\Controllers\Api\\'.ucfirst($controller).'Controller';
        $con     = new $controller($request);
        if (preg_match('/^[a-zA-Z][a-zA-Z0-9_]+/is', $action)) {
            if (method_exists($con, $action)) {
                return $con->{$action}($request);
//                return \App::call([$con, $action]);
            }
        }
        die('No route found , Please check url parameters');
    });

});
